﻿//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace 享元模式
//{
//    internal class Program
//    {
//        static void Main(string[] args)
//        {
//            int externalState = 10;
//            FlyweightManager manager = new FlyweightManager();

//            Flyweight fa = manager.GetFlyweight("A");
//            if (fa != null )
//            {
//                fa.Print(--externalState);
//            }
//            Flyweight fb = manager.GetFlyweight("B");
//            if (fb != null)
//            {
//                fb.Print(--externalState);
//            }
//            Flyweight fc = manager.GetFlyweight("C");
//            if (fa != null)
//            {
//                fc.Print(--externalState);
//            }
//            Flyweight fd = manager.GetFlyweight("A");
//            if (fd != null)
//            {
//                fa.Print(--externalState);
//            }
//            else
//            {
//                manager.flyweights.Add("D", new Flyweight("D"));
//                fd = manager.GetFlyweight("D");
//            }
//            fd.Print(--externalState);
//            fc.Print(--externalState);
//            fa.Print(--externalState);
//            fa.Print(--externalState);
//        }
//    }

//    class Flyweight
//    {
//        private string intrinsicState;

//        public Flyweight(string intrinsicState)
//        {
//            this.intrinsicState = intrinsicState;
//        }

//        public void Print(int extrinsicstate)
//        {
//            Console.WriteLine($"具体使用文本：内部状态{intrinsicState} 外部状态{extrinsicstate}");
//        }
//    }

//    class FlyweightManager
//    {
//        public Hashtable flyweights = new Hashtable();
//        public FlyweightManager()
//        {
//            flyweights.Add("A", new Flyweight("A"));
//            flyweights.Add("B", new Flyweight("B"));
//            flyweights.Add("C", new Flyweight("C"));
//        }

//        public Flyweight GetFlyweight(object key)
//        {
//            return flyweights[key] as Flyweight;
//        }
//    }
//}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProxyPattern
{
    internal class Program
    {
        static void Main(string[] args)
        {

            Friend friend = new Friend();
            friend.BuyProduct();

            Console.ReadKey();
        }
    }
    //需求方
    class Person
    {
        public void BuyProduct()
        {
            Console.WriteLine("购买手机产品");
        }
    }

    //代理方
    class Friend
    {
        Person person;
        public Friend()
        {
            person = new Person();
        }
        public void BuyProduct()
        {
            PreBuyProduct();
            person.BuyProduct();
            PostBuyProduct();
        }
        private void PostBuyProduct()
        {
            Console.WriteLine("-----------");
            Console.WriteLine("购买产品礼盒");
            Console.WriteLine("-----------");
        }
        private void PreBuyProduct()
        {
            Console.WriteLine("-----------");
            Console.WriteLine("设计购买清单");
            Console.WriteLine("-----------");
        }
    }
}

